package com.vv.images;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @Description
 * @Author xingchao
 * @Date 2021/2/3 10:22
 */
public class ImageTest {
    String[] file_server  = {"182.118.27.17", "218.92.217.27"};
    String[] new_file_server   = {"182.118.58.159", "218.92.217.28"};
    public static void main(String[] args)  {

        // 1、根据链接访问 fastDFS 下载原图
        // 2、获取尺寸、 目标格式   进行裁图 转码
        // 3、处理后的图片上传到dfs、
        // 4、返回图片 流、Base64、response
    }


    public  static Map<String, Object>   dealCommonFile(String ext, String filename, String host, Integer width, Integer height, String oldpath, Integer type, String trans) throws IOException {
        Map<String, Object> map = new HashMap<>();
        //    common_operate = {"zoom": 1, "crop": 2}
        String[] file_ext_list ={"jpg", "jpeg", "bmp", "png", "webp", "gif", "psd", "tga", "tiff"};
        String[]  ext_list = {"webp", "jpeg", "jpg", "gif", "png", "bmp"};
        if (1 != type && 2 != type){
            map.put("code",400);
            return  map;
        }

        // 获取文件类型
        String from_ext = filename.substring(filename.lastIndexOf(".") + 1);

        String tempfile = UUID.randomUUID().toString()+from_ext;
        tempfile="文件路径"+tempfile;

        if (!filename.startsWith("/")){
            filename = "/" + filename;
        }
        String local_file = "路径+md5（文件名）.后缀";
        //  zoom  压缩
        if (type == 1){
            if(0 == height || 0 == width){
                BufferedImage image = ImageIO.read(new File(filename));
                int imageWidth = image.getWidth();
                int imageHeight = image.getHeight();
//                zoom_image(local_file,tempfile,imageWidth,imageHeight,true,true,"trans");
            }
        }else {
            // 旋转
            // 获取图片信息   local_file
            HashMap<String, Object> exifinfo = new HashMap<>();
/*
            Orientation = 1（不翻转）
            Orientation = 2（左右翻转）
            Orientation = 3（180度翻转）
            Orientation = 4（上下翻转）
            Orientation = 5（顺时针翻转90度后，左右翻转）
            Orientation = 6（顺时针翻转90度）
            Orientation = 7（逆时针翻转90度后，左右翻转）
            Orientation = 8（逆时针翻转90度）
            */

            if (exifinfo.containsKey("Orientation")){
                Object orientation = exifinfo.get("Orientation");

            }
//            zoom_image(local_file,tempfile,imageWidth,imageHeight,true,true,"trans");
        }
        return  null;
    }
}
